package com.halixun.d2app.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * @ProjectName: D2App
 * @Package: com.halixun.d2app.utils
 * @ClassName: DateUtil
 * @Description: java类作用描述
 * @Author: hdx
 * @CreateDate: 2019/11/30 11:47
 * @UpdateUser: hdx
 * @UpdateDate: 2019/11/30 11:47
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class DateUtil {
    /*获取系统时间 格式为："yyyy/MM/dd "*/
    public static String getCurrentDate() {
        Date d = new Date();
        SimpleDateFormat sf = new SimpleDateFormat("yyyy年MM月dd日",Locale.CHINA);
        return sf.format(d);
    }

    /*时间戳转换成字符窜*/
    public static String getDateToString(long time) {
        Date d = new Date(time*1000);
        SimpleDateFormat sf = new SimpleDateFormat("yyyy年MM月dd日",Locale.CHINA);
        return sf.format(d);
    }


    /*时间戳转换成字符窜*/
    public static String getDateToString2(long time) {
        Date d = new Date(time*1000);
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss", Locale.CHINA);
        return sf.format(d);
    }

    /*时间戳转换成字符窜*/
    public static String getDateToString2(long time,String format) {
        Date d = new Date(time*1000);
        SimpleDateFormat sf = new SimpleDateFormat(format,Locale.CHINA);
        return sf.format(d);
    }


    /*将字符串转为时间戳*/
    public static long getStringToDate(String time) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日",Locale.CHINA);
        Date date = new Date();
        try{
            date = sdf.parse(time);
        } catch(ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return date.getTime();
    }
}
